<?php require_once('../../g-config/konek.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "index.php?stat=logout";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_admin = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_admin = $_SESSION['MM_Username'];
}
mysql_select_db($database_konek, $konek);
$query_admin = sprintf("SELECT * FROM data_user WHERE nama_user = %s", GetSQLValueString($colname_admin, "text"));
$admin = mysql_query($query_admin, $konek) or die(mysql_error());
$row_admin = mysql_fetch_assoc($admin);
$totalRows_admin = mysql_num_rows($admin);

$colname_data_menu = "-1";
if (isset($_GET['id_menu'])) {
  $colname_data_menu = $_GET['id_menu'];
}
mysql_select_db($database_konek, $konek);
$query_data_menu = sprintf("SELECT * FROM menu WHERE id = %s", GetSQLValueString($colname_data_menu, "int"));
$data_menu = mysql_query($query_data_menu, $konek) or die(mysql_error());
$row_data_menu = mysql_fetch_assoc($data_menu);
$totalRows_data_menu = mysql_num_rows($data_menu);
?>

  <?php
if ($totalRows_data_menu>0){

$deleteMENU = sprintf("DELETE FROM menu WHERE id=%s",
                       GetSQLValueString($_GET['id_menu'], "int"));

  mysql_select_db($database_konek, $konek);
  $Result1 = mysql_query($deleteMENU, $konek) or die(mysql_error());
  
$colname_sett_review = "-1";
if (isset($row_data_menu['id'])) {
  $colname_sett_review = $row_data_menu['id'];
}
mysql_select_db($database_konek, $konek);
$query_sett_review = sprintf("SELECT * FROM plug_review WHERE id_menu = %s ORDER BY id ASC", GetSQLValueString($colname_sett_review, "int"));
$sett_review = mysql_query($query_sett_review, $konek) or die(mysql_error());
$row_sett_review = mysql_fetch_assoc($sett_review);
$totalRows_sett_review = mysql_num_rows($sett_review);

if ($totalRows_sett_review>0){
do {

$deletesett_review = sprintf("DELETE FROM plug_review WHERE id_menu=%s",
                       GetSQLValueString($row_data_menu['id'], "int"));

  mysql_select_db($database_konek, $konek);
  $Result1 = mysql_query($deletesett_review, $konek) or die(mysql_error());



mysql_free_result($plug_review);
} while ($row_sett_review = mysql_fetch_assoc($sett_review));
}

mysql_free_result($sett_review);
  
?>
	
	 <script language="javascript">
  	<!--
     	    alert('Delete Success')
			window.location = "../home.php?page=page";
			
   	--></script>
	<?php
}?>

<?php
mysql_free_result($admin);

mysql_free_result($data_menu);
?>
